package com.swan.core.utils.core;

import com.swan.core.enums.SwanExCodeEnum;
import com.swan.core.exception.ISwanExceptionEnum;
import com.swan.core.exception.SwanBaseException;

import java.util.Collection;
import java.util.Map;

/**
 * @author zongf
 * @date 2025-02-13
 **/
public class AssertUtil {

    public static void isTrue(Boolean trueObject, String message) {
        isTrue(trueObject, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isTrue(Boolean trueObject, ISwanExceptionEnum exceptionEnum) {
        isTrue(trueObject, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isTrue(Boolean trueObject, int code, String message) {
        if (!trueObject) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isFalse(Boolean falseObject, String message) {
        isFalse(falseObject, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isFalse(Boolean falseObject, ISwanExceptionEnum exceptionEnum) {
        isFalse(falseObject, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isFalse(Boolean falseObject, int code, String message) {
        if (falseObject !=null && falseObject) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isNull(Object nullObject, String message) {
       isNull(nullObject, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isNull(Object nullObject, ISwanExceptionEnum exceptionEnum) {
        isNull(nullObject, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isNull(Object nullObject, int code, String message) {
        if (nullObject != null) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void notNull(Object object, String message) {
        notNull(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void notNull(Object object, ISwanExceptionEnum exceptionEnum) {
        notNull(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void notNull(Object object, int code, String message) {
        if (object == null) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isEmpty(String object, String message) {
        isEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isEmpty(String object, ISwanExceptionEnum exceptionEnum) {
        isEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isEmpty(String object, int code, String message) {
        if (object != null && object.trim().length() > 0) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isNotEmpty(String object, String message) {
        isNotEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isNotEmpty(String object, ISwanExceptionEnum exceptionEnum) {
        isNotEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isNotEmpty(String object, int code, String message) {
        if (object == null || object.trim().length() == 0) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isEmpty(Collection object, String message) {
        isEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isEmpty(Collection object, ISwanExceptionEnum exceptionEnum) {
        isEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isEmpty(Collection object, int code, String message) {
        if (object != null && object.size() > 0) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isNotEmpty(Collection object, String message) {
        isNotEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isNotEmpty(Collection object, ISwanExceptionEnum exceptionEnum) {
        isNotEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isNotEmpty(Collection object, int code, String message) {
        if (object == null || object.size() == 0) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isEmpty(Map object, String message) {
        isEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isEmpty(Map object, ISwanExceptionEnum exceptionEnum) {
        isEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isEmpty(Map object, int code, String message) {
        if (object != null && object.size() > 0) {
            throw new SwanBaseException(code, message);
        }
    }

    public static void isNotEmpty(Map object, String message) {
        isNotEmpty(object, SwanExCodeEnum.PARAM_ERROR.code(), message);
    }

    public static void isNotEmpty(Map object, ISwanExceptionEnum exceptionEnum) {
        isNotEmpty(object, exceptionEnum.code(), exceptionEnum.message());
    }

    public static void isNotEmpty(Map object, int code, String message) {
        if (object == null || object.size() == 0) {
            throw new SwanBaseException(code, message);
        }
    }



}
